package util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MyUtil {
	public static String Encry(String source,String type){
		MessageDigest digest=null;
		try {
			digest = MessageDigest.getInstance(type);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		byte[] md=digest.digest(source.getBytes());
		StringBuilder sb=new StringBuilder();
		for(byte b:md){
			String stemp=Integer.toHexString(b);
			int len=stemp.length();
			if(len>2){
				stemp=stemp.substring(len-2);
			}
			else if(len<2){
				stemp+="0";
			}
			sb.append(stemp);
		}
		return sb.toString();
	}
}
